package cn.lzj.org.controller;

import cn.lzj.org.service.IShopAuditLogService;
import cn.lzj.org.domain.ShopAuditLog;
import cn.lzj.org.query.ShopAuditLogQuery;
import cn.lzj.basic.util.AjaxResult;
import cn.lzj.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/shopAuditLog")
public class ShopAuditLogController {

    @Autowired
    public IShopAuditLogService shopAuditLogService;

    /**
     * 接口：添加或修改
     * @param shopAuditLog  传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null){
                    shopAuditLogService.update(shopAuditLog);
            }else{
                    shopAuditLogService.add(shopAuditLog);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.util().setmessage("噢哟，系统报错了，我们正在殴打程序员！！!");
        }
    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.util().setmessage("噢哟，系统报错了，我们正在殴打程序员！！!");
        }
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult removeList(@RequestBody List<Long> ids){
        try {
                shopAuditLogService.removeList(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.util().setmessage("噢哟，系统报错了，我们正在殴打程序员！！!");
        }
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}")
    public ShopAuditLog queryById(@PathVariable("id")Long id) {
        return shopAuditLogService.queryById(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<ShopAuditLog> queryAll(){
        return shopAuditLogService.queryAll();
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public PageList<ShopAuditLog> queryPage(@RequestBody ShopAuditLogQuery query) {
        return shopAuditLogService.queryPage(query);
    }
}
